package com.hksj.em.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.hksj.base.vo.ChartVO;
import com.hksj.common.core.model.Rest;
import com.hksj.em.query.RoomEnvChartQuery;
import com.hksj.em.query.RoomEnvQuery;
import com.hksj.em.service.RoomEnvService;
import com.hksj.em.vo.RoomEnvVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletResponse;
import java.util.Map;

@Api(tags = "房间环境参数")
@RestController
@RequestMapping("/roomEnv")
public class RoomEnvController {
    @Autowired
    private RoomEnvService roomEnvService;

    @ApiOperation(value = "分页查询房间环境参数",response = RoomEnvVO.class)
    @PostMapping("/pageRoomEnv")
    public Rest<IPage<RoomEnvVO>> pageRoomEnv(@RequestBody RoomEnvQuery query){
        IPage<RoomEnvVO> page = roomEnvService.pageRoomEnv(query);
        return Rest.ok(page);
    }

    @ApiOperation(value = "导出房间环境参数")
    @PostMapping("/exportRoomEnv")
    public void exportRoomEnv(@RequestBody RoomEnvQuery query, HttpServletResponse response){
        roomEnvService.exportRoomEnv(query,response);
    }

    @ApiOperation(value = "房间-查询设备各属性折线图",response = ChartVO.class)
    @PostMapping("/listChartData")
    public Rest<Map<String,ChartVO>> listChartData(@RequestBody @Validated RoomEnvChartQuery query){
        Map<String,ChartVO> map = roomEnvService.listChartData(query);
        return Rest.ok(map);
    }
}
